/**
 * Created by Administrator on 2017/6/28.
 */
/**
 * Created by Administrator on 2017/6/14.
 */
import React from 'react';
import {
    Text,WebView,StyleSheet,View
} from 'react-native';
import { TabNavigator,StackNavigator,DrawerNavigator } from "react-navigation";

//测试提交
const REQUEST_URL = 'http://c.m.163.com/nc/article/';
export default class Home extends React.Component {

    static navigationOptions  = ({ navigation }) => ({
        title: ` ${navigation.state.params.user.title}`,
    });

    constructor(props) {
        super(props);
        this.
            state = {
            details: null,
        };
    }

    componentDidMount() {
        this.fetchData();
    }

    fetchData() {
        var a = REQUEST_URL+this.props.navigation.state.params.user.postid+'/full.html'
        let b = this.props.navigation.state.params.user.postid
        fetch(REQUEST_URL+this.props.navigation.state.params.user.postid+'/full.html', {
            method: 'GET',
        })
            .then((responseData) => {
                let bb = JSON.stringify(responseData)
                // console.warn('data:'+bb)
                let data = JSON.parse(responseData._bodyInit)
                // console.warn('data:'+JSON.stringify(data))
                this.setState({
                    details: data[b]
                });
            })
            .catch((error) => {
                console.log('fateError'+error.toString())
            });
    }

    _featData(){
        fetch(REQUEST_URL,{
            method:'GET'
        })
            .then((response) => response.json())
            .then((responseData) => {
                this.setState({
                    details: responseData.CMTSG7NV000189FH
                });
            })
            .catch((error) => {
                console.log('fateError'+error.toString())
            });
    }

    render(){
        if (!this.state.details) {
            return this.renderLoadingView();
        }
        return this.renderMovie();
    }

    renderLoadingView() {
        return (
            <View style={{flex:1}}>
                <Text>
                    正在加载电影数据......
                </Text>
            </View>
        );
    }

    renderMovie() {
        return (
            <View style={{flex:1}}>
                <WebView source={{html:this.state.details.body}}/>
            </View>
        );
    }
}
